﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace threadState
{
    internal class Thread
    {
        // 当前线程的状态
        public State CurrentState { get; set; } = new New();
        // 线程的ID
        public int ThreadId { get; set; }

        // 从就绪状态获取CPU，进入运行状态
        public void GetCPU()
        {
            ((Ready)CurrentState).GetCPU(this);
        }

        // 从阻塞状态恢复，回到就绪状态
        public void Resume()
        {
            ((Blocked)CurrentState).Resume(this);
        }

        // 从新建状态开始，进入就绪状态
        public void Start()
        {
            ((New)CurrentState).Start(this);
        }

        // 从运行状态停止，进入死亡状态
        public void Stop()
        {
            ((Running)CurrentState).Stop(this);
        }

        // 从运行状态挂起，进入阻塞状态
        public void Suspend()
        {
            ((Running)CurrentState).Suspend(this);
        }
    }
}
